import Taro from '@tarojs/taro'

/**
 * 存储数据
 * @param key 存储键
 * @param data 存储数据
 */
export const setStorage = (key: string, data: any): Promise<void> => {
  return Taro.setStorage({
    key,
    data
  })
}

/**
 * 同步存储数据
 * @param key 存储键
 * @param data 存储数据
 */
export const setStorageSync = (key: string, data: any): void => {
  return Taro.setStorageSync(key, data)
}

/**
 * 获取存储数据
 * @param key 存储键
 */
export const getStorage = (key: string): Promise<any> => {
  return Taro.getStorage({
    key
  }).then(res => res.data)
}

/**
 * 同步获取存储数据
 * @param key 存储键
 */
export const getStorageSync = (key: string): any => {
  return Taro.getStorageSync(key)
}

/**
 * 删除存储数据
 * @param key 存储键
 */
export const removeStorage = (key: string): Promise<void> => {
  return Taro.removeStorage({
    key
  })
}

/**
 * 同步删除存储数据
 * @param key 存储键
 */
export const removeStorageSync = (key: string): void => {
  return Taro.removeStorageSync(key)
}

/**
 * 清空所有存储数据
 */
export const clearStorage = (): Promise<void> => {
  return Taro.clearStorage()
}

/**
 * 同步清空所有存储数据
 */
export const clearStorageSync = (): void => {
  return Taro.clearStorageSync()
}

/**
 * 获取存储信息
 */
export const getStorageInfo = (): Promise<Taro.getStorageInfo.Result> => {
  return Taro.getStorageInfo()
}

/**
 * 同步获取存储信息
 */
export const getStorageInfoSync = (): Taro.getStorageInfoSync.Result => {
  return Taro.getStorageInfoSync()
} 